(function(){"use strict";BX.namespace("BX.Landing.UI.Panel");var t=BX.Landing.Utils.removeClass;var n=BX.Landing.Utils.addClass;var e=BX.Landing.Utils.onCustomEvent;var i=BX.Landing.Utils.bind;var a=BX.Landing.Utils.makeFilterablePopupMenu;var s=BX.Landing.Utils.makeSelectablePopupMenu;var o=BX.Landing.Utils.style;var d=BX.Landing.Utils.encodeDataValue;BX.Landing.UI.Panel.Top=function(t,n){BX.Landing.UI.Panel.BasePanel.apply(this,arguments);this.layout=document.querySelector(".landing-ui-panel-top");this.siteButton=this.layout.querySelector(".landing-ui-panel-top-chain-link-site");this.pageButton=this.layout.querySelector(".landing-ui-panel-top-chain-link-page");this.undoButton=this.layout.querySelector(".landing-ui-panel-top-history-undo");this.redoButton=this.layout.querySelector(".landing-ui-panel-top-history-redo");this.desktopButton=this.layout.querySelector(".landing-ui-button-desktop");this.tabletButton=this.layout.querySelector(".landing-ui-button-tablet");this.mobileButton=this.layout.querySelector(".landing-ui-button-mobile");this.iframeWrapper=document.querySelector(".landing-ui-view-iframe-wrapper");this.iframe=document.querySelector(".landing-ui-view");this.lastActive=this.desktopButton;this.loader=null;this.onDesktopSizeChange=this.onDesktopSizeChange.bind(this);this.onTabletSizeChange=this.onTabletSizeChange.bind(this);this.onMobileSizeChange=this.onMobileSizeChange.bind(this);this.onIframeClick=this.onIframeClick.bind(this);this.onSiteButtonClick=this.onSiteButtonClick.bind(this);this.onPageButtonClick=this.onPageButtonClick.bind(this);this.onUndo=this.onUndo.bind(this);this.onRedo=this.onRedo.bind(this);this.onKeyDown=this.onKeyDown.bind(this);this.adjustHistoryButtonsState=this.adjustHistoryButtonsState.bind(this);i(this.desktopButton,"click",this.onDesktopSizeChange);i(this.tabletButton,"click",this.onTabletSizeChange);i(this.mobileButton,"click",this.onMobileSizeChange);i(this.iframe.contentDocument,"click",this.onIframeClick);i(this.undoButton,"click",this.onUndo);i(this.redoButton,"click",this.onRedo);i(document,"keydown",this.onKeyDown);e(document,"iframe:keydown",this.onKeyDown);e(window,"BX.Landing.History:init",this.adjustHistoryButtonsState);e(window,"BX.Landing.History:update",this.adjustHistoryButtonsState);var a=parseInt(BX.Landing.Main.getInstance().options.sites_count);var s=parseInt(BX.Landing.Main.getInstance().options.pages_count);if(a>1&&this.siteButton){i(this.siteButton,"click",this.onSiteButtonClick)}if(s>1&&this.pageButton){i(this.pageButton,"click",this.onPageButtonClick)}var o=BX.Landing.PageObject.getRootWindow();var d=o.BX.getClass("BX.Landing.History");if(d){o.BX.Landing.History.instance=null}BX.Landing.History.getInstance()};BX.Landing.UI.Panel.Top.instance=null;BX.Landing.UI.Panel.Top.getInstance=function(){var t=BX.Landing.PageObject.getRootWindow();if(!t.BX.Landing.UI.Panel.Top.instance){t.BX.Landing.UI.Panel.Top.instance=new BX.Landing.UI.Panel.Top("top_panel")}return t.BX.Landing.UI.Panel.Top.instance};BX.Landing.UI.Panel.Top.prototype={constructor:BX.Landing.UI.Panel.Top,__proto__:BX.Landing.UI.Panel.BasePanel.prototype,superclass:BX.Landing.UI.Panel.BasePanel.prototype,onKeyDown:function(t){var n=t.keyCode||t.which;if(n===90&&(window.navigator.userAgent.match(/win/i)?t.ctrlKey:t.metaKey)){var e=BX.Landing.PageObject.getRootWindow();var i=e.BX.Reflection.getClass("BX.Landing.UI.Panel.FormSettingsPanel");if(!i||!i.getInstance().isShown()){if(t.shiftKey){t.preventDefault();this.onRedo()}else{t.preventDefault();this.onUndo()}}}},onUndo:function(){if(BX.Landing.History.getInstance().canUndo()&&!this.undoButton.hasAttribute("data-disabled")){this.getLoader().show(this.undoButton);n(this.undoButton,"landing-ui-onload");BX.Landing.History.getInstance().undo().then(function(){this.getLoader().hide();t(this.undoButton,"landing-ui-onload")}.bind(this))}else{this.getLoader().hide();t(this.undoButton,"landing-ui-onload")}},onRedo:function(){if(BX.Landing.History.getInstance().canRedo()&&!this.redoButton.hasAttribute("data-disabled")){this.getLoader().show(this.redoButton);n(this.redoButton,"landing-ui-onload");BX.Landing.History.getInstance().redo().then(function(){this.getLoader().hide();t(this.redoButton,"landing-ui-onload")}.bind(this))}else{this.getLoader().hide();t(this.redoButton,"landing-ui-onload")}},getLoader:function(){if(this.loader===null){this.loader=new BX.Loader({size:23,offset:{top:"3px",left:"1px"}});void o(this.loader.layout.querySelector(".main-ui-loader-svg-circle"),{"stroke-width":"4px"});void o(this.loader.layout.querySelector(".main-ui-loader-svg"),{"margin-top":"-3px"})}return this.loader},adjustHistoryButtonsState:function(t){if(t.canUndo()){this.undoButton.classList.remove("landing-ui-disabled");this.undoButton.removeAttribute("data-disabled")}else{this.undoButton.classList.add("landing-ui-disabled")}if(t.canRedo()){this.redoButton.classList.remove("landing-ui-disabled");this.redoButton.removeAttribute("data-disabled")}else{this.redoButton.classList.add("landing-ui-disabled")}},disableHistory:function(){this.undoButton.classList.add("landing-ui-disabled");this.undoButton.setAttribute("data-disabled","");this.redoButton.classList.add("landing-ui-disabled");this.redoButton.setAttribute("data-disabled","")},enableHistory:function(){this.adjustHistoryButtonsState(BX.Landing.History.getInstance())},disableDevices:function(){this.desktopButton.classList.add("landing-ui-disabled");this.tabletButton.classList.add("landing-ui-disabled");this.mobileButton.classList.add("landing-ui-disabled")},enableDevices:function(){this.desktopButton.classList.remove("landing-ui-disabled");this.tabletButton.classList.remove("landing-ui-disabled");this.mobileButton.classList.remove("landing-ui-disabled")},onDesktopSizeChange:function(){this.lastActive.classList.remove("active");this.lastActive=this.desktopButton;this.desktopButton.classList.add("active");BX.DOM.write(function(){this.iframeWrapper.style.width=null}.bind(this));document.body.setAttribute("data-device","desktop");BX.Landing.Main.getInstance().setDeviceCode("desktop");this.iframeWrapper.dataset.postfix="";BX.Landing.Main.getInstance().enableControls();BX.Landing.Main.getInstance().setNoTouchDevice();BX.Landing.Main.getInstance().makeControlsInternal();BX.Landing.UI.Panel.StylePanel.getInstance().hide();BX.onCustomEvent("BX.Landing.Main:editorSizeChange",["desktop"])},onTabletSizeChange:function(){this.lastActive.classList.remove("active");this.lastActive=this.tabletButton;this.tabletButton.classList.add("active");BX.DOM.write(function(){this.iframeWrapper.style.width="990px"}.bind(this));document.body.setAttribute("data-device","tablet");BX.Landing.Main.getInstance().setDeviceCode("tablet");this.iframeWrapper.dataset.postfix="--md";BX.Landing.Main.getInstance().setTouchDevice();BX.Landing.Main.getInstance().makeControlsInternal();BX.Landing.UI.Panel.StylePanel.getInstance().hide();BX.onCustomEvent("BX.Landing.Main:editorSizeChange",["tablet"])},onMobileSizeChange:function(){this.lastActive.classList.remove("active");this.lastActive=this.mobileButton;this.mobileButton.classList.add("active");BX.DOM.write(function(){this.iframeWrapper.style.width="375px"}.bind(this));document.body.setAttribute("data-device","mobile");BX.Landing.Main.getInstance().setDeviceCode("mobile");this.iframeWrapper.dataset.postfix="--md";BX.Landing.Main.getInstance().setTouchDevice();BX.Landing.Main.getInstance().makeControlsExternal();BX.Landing.UI.Panel.StylePanel.getInstance().hide();BX.onCustomEvent("BX.Landing.Main:editorSizeChange",["mobile"])},onSiteButtonClick:function(t){t.preventDefault();if(!this.siteMenu){var n=new BX.Loader({size:40});this.siteMenu=new BX.PopupMenuWindow({id:"site_list_menu",bindElement:this.siteButton,events:{onPopupClose:function(){this.siteButton.classList.remove("landing-ui-active");this.siteButton.blur()}.bind(this)},menuShowDelay:0,offsetTop:9});this.siteMenu.popupWindow.contentContainer.style.minHeight="60px";this.siteMenu.popupWindow.contentContainer.style.minWidth="160px";n.show(this.siteMenu.popupWindow.contentContainer);var e={siteId:BX.Landing.Main.getInstance().options.site_id,landingId:BX.Landing.Main.getInstance().id,filter:{"=TYPE":BX.Landing.Main.getInstance().options.params.type,SPECIAL:"N"}};BX.Landing.Backend.getInstance().getSites(e).then((function(t){return new Promise((function(n){setTimeout(n.bind(null,t),300)}))})).then(function(t){a(this.siteMenu);s(this.siteMenu);t.forEach((function(t){this.siteMenu.addMenuItem({id:t.ID,text:d(t.TITLE),items:function(){var n=[];var e=BX.Landing.Main.getInstance().options.params.sef_url.site_edit;var i=BX.Landing.Main.getInstance().options.params.sef_url.site_show;n.push({text:BX.Landing.Loc.getMessage("LANDING_ENTITIES_MENU_PAGES_LIST"),href:i.replace("#site_show#",t.ID)});n.push({text:BX.Landing.Loc.getMessage("LANDING_ENTITIES_MENU_EDIT"),href:e.replace("#site_edit#",t.ID)});return n}()})}),this);n.hide()}.bind(this))}this.siteButton.classList.add("landing-ui-active");this.siteMenu.show()},onPageButtonClick:function(t){t.preventDefault();if(!this.pageMenu){var n=new BX.Loader({size:40});this.pageMenu=new BX.PopupMenuWindow({id:"page_list_menu",bindElement:this.pageButton,events:{onPopupClose:function(){this.pageButton.classList.remove("landing-ui-active");this.pageButton.blur()}.bind(this)},menuShowDelay:0,offsetTop:9});this.pageMenu.popupWindow.contentContainer.style.minHeight="60px";this.pageMenu.popupWindow.contentContainer.style.minWidth="160px";n.show(this.pageMenu.popupWindow.contentContainer);var e={siteId:BX.Landing.Main.getInstance().options.site_id,landingId:BX.Landing.Main.getInstance().id,filter:{"=TYPE":BX.Landing.Main.getInstance().options.params.type}};BX.Landing.Backend.getInstance().getLandings({siteId:e.siteId}).then((function(t){return new Promise((function(n){setTimeout(n.bind(null,t),300)}))})).then(function(t){a(this.pageMenu);s(this.pageMenu);t.forEach((function(t){if((t.FOLDER_ID===null||parseInt(t.FOLDER_ID)===0)&&!t.IS_AREA){this.pageMenu.addMenuItem({id:t.ID,text:d(t.TITLE),items:function(){var n=[];var e=BX.Landing.Main.getInstance().options.params.sef_url.landing_edit;var i=BX.Landing.Main.getInstance().options.params.sef_url.landing_view;if(t.FOLDER==="Y"){var a=BX.Landing.Main.getInstance().options.params.sef_url.site_show;n.push({text:BX.Landing.Loc.getMessage("LANDING_ENTITIES_MENU_PAGES_LIST"),href:BX.Landing.Utils.addQueryParams(a.replace("#site_show#",t.SITE_ID),{folderId:t.ID})})}n.push({text:BX.Landing.Loc.getMessage("LANDING_ENTITIES_MENU_PAGES_EDIT"),href:i.replace("#site_show#",t.SITE_ID).replace("#landing_edit#",t.ID)});n.push({text:BX.Landing.Loc.getMessage("LANDING_ENTITIES_MENU_PAGES_SETTINGS"),href:e.replace("#site_show#",t.SITE_ID).replace("#landing_edit#",t.ID)});return n}()})}}),this);requestAnimationFrame((function(){n.hide()}))}.bind(this))}this.pageButton.classList.add("landing-ui-active");this.pageMenu.show()},onIframeClick:function(){if(this.siteMenu){this.siteMenu.close()}if(this.pageMenu){this.pageMenu.close()}},getFormNameLayout:function(){return this.layout.querySelector(".landing-ui-panel-top-form-name")},setFormName:function(t){if(BX.Type.isString(t)){var n=this.getFormNameLayout();if(BX.Type.isDomNode(n)){n.firstElementChild.textContent=t;n.firstElementChild.setAttribute("title",t)}}}}})();
//# sourceMappingURL=top_panel.map.js